package com.nice.nice201110.service;

import com.nice.nice201110.entity.TNews;
import com.nice.nice201110.entity.TNewsAccept;
import com.nice.nice201110.entity.TNiceFile;
import com.nice.nice201110.entity.TOrganization;
import com.nice.nice201110.mapper.TNewsAcceptMapper;
import com.nice.nice201110.mapper.TNewsMapper;
import com.nice.nice201110.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TnewService {

    @Autowired
    TNewsMapper tNewsMapper;   //消息dao

    @Autowired
    TNewsAcceptMapper tNewsAcceptMapper;  //接受消息

    private TNewsAccept tNewsAccept = new TNewsAccept();
    //查看所有消息
    public List<TNews> getAll(UserVo userVo){
        return tNewsMapper.selectByUsers(userVo);
    }
    //插入消息(插入组织)
    public Boolean insert(TNews tNews, Integer tOrganizationid){
        if(tNews!=null) {
            tNews.setDate(new Date());
            int newNum = tNewsMapper.insertSelective(tNews);
            if(newNum>0){
                int newID = tNews.getId();
                tNewsAccept.setLtype("1");
                tNewsAccept.setPid(tOrganizationid);
                tNewsAcceptMapper.insertSelective(tNewsAccept);
            }else{
                return false;
            }
        }
        return true;
    }

}
